package dao.impl;

import dao.UserDao;
import pojo.User;

import java.util.*;

public class UserDaoImpl implements UserDao {
    /**
     * 将基本类型的属性通过setter注入到Spring容器中
     */
    private String username;
    private int age;

    public void setUsername(String username) {
        this.username = username;
    }

    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 将集合类型的属性注入到Spring容器
     */
    private List<String> strList;
    private Map<String, User> userMap;
    private Properties prop;

    public void setStrList(List<String> strList) {
        this.strList = strList;
    }

    public void setUserMap(Map<String, User> userMap) {
        this.userMap = userMap;
    }

    public void setProp(Properties prop) {
        this.prop = prop;
    }

    /**
     * 通过空参构造方法将这个bean存入Spring容器
     */
    public UserDaoImpl() {
        System.out.println("UserDaoImpl对象创建...");
    }

    /**
     * 初始化方法和销毁方法，在配置文件的bean属性中配置
     * init-method="初始化方法名"
     * destroy-method="销毁方法名"
     * 初始化方法会在配置文件加载时进行初始化，销毁方法会在容器销毁时执行
     */
    public void init(){
        System.out.println("UserDaoImpl初始化方法运行...");
    }
    public void destroy(){
        System.out.println("UserDaoImpl销毁方法运行...");
    }

    /**
     * 业务方法
     */
    public void save() {
        System.out.println("strList = " + strList);
        System.out.println("userMap = " + userMap);
        System.out.println("prop = " + prop);
        System.out.println("username = " + username);
        System.out.println("age = " + age);
        System.out.println("save running...");
    }
}
